From df0f369f9f556a46831d79d2e53c9324191ffe06 Mon Sep 17 00:00:00 2001 From: alexmot Date: Wed, 23 Jul 2003 13:56:49 +0000 Subject: [PATCH] Fix waypoint output indexes when using multiple output files in xcsv and Topo! --- gpsbabel/csv_util.c | 11 ++++++++--- gpsbabel/tpg.c | 8 +++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/gpsbabel/csv_util.c b/gpsbabel/csv_util.c index c6014dc73..f358626c2 100644 --- a/gpsbabel/csv_util.c +++ b/gpsbabel/csv_util.c @@ -37,6 +37,8 @@ extern char *xcsv_urlbase; extern char *prefer_shortnames; +static int waypt_out_count; + /*********************************************************************/ /* csv_stringclean() - remove any unwanted characters from string. */ /* returns copy of string. */ @@ -579,7 +581,6 @@ static void xcsv_waypt_pr(const waypoint *wpt) { char buff[1024]; - static int index = 0; char *shortname = NULL; char *description = NULL; char * anyname = NULL; @@ -633,7 +634,7 @@ xcsv_waypt_pr(const waypoint *wpt) sprintf(buff, fmp->printfc, ""); } else if (strcmp(fmp->key, "INDEX") == 0) { - sprintf(buff, fmp->printfc, index + atoi(fmp->val)); + sprintf(buff, fmp->printfc, waypt_out_count + atoi(fmp->val)); } else if (strcmp(fmp->key, "CONSTANT") == 0) { sprintf(buff, fmp->printfc, fmp->val); @@ -792,7 +793,8 @@ xcsv_waypt_pr(const waypoint *wpt) if (description && description != shortname) xfree(description); - index++; + /* increment the index counter */ + waypt_out_count++; } static void @@ -811,6 +813,9 @@ xcsv_data_write(void) queue *elem, *tmp; ogue_t *ogp; + /* reset the index counter */ + waypt_out_count = 0; + /* output prologue lines, if any. */ QUEUE_FOR_EACH(&xcsv_file.prologue, elem, tmp) { ogp = (ogue_t *) elem; diff --git a/gpsbabel/tpg.c b/gpsbabel/tpg.c index 777638e67..ac62d1261 100644 --- a/gpsbabel/tpg.c +++ b/gpsbabel/tpg.c @@ -34,6 +34,7 @@ static void *mkshort_handle; static int i_am_little_endian; static int endianness_tested; +static int waypt_out_count; static void test_endianness(void) @@ -152,6 +153,8 @@ tpg_wr_init(const char *fname, const char *args) if (tpg_file_out == NULL) { fatal(MYNAME ": Cannot open %s for writing\n", fname); } + + waypt_out_count = 0; } static void @@ -256,7 +259,6 @@ tpg_waypt_pr(const waypoint *wpt) char c; char *shortname; char *description; - static int out_count = 0; /* these unknown 4 are probably point properties (color, icon, etc..) */ unsigned char unknown4[] = { 0x78, 0x56, 0x34, 0x12 }; @@ -265,7 +267,7 @@ tpg_waypt_pr(const waypoint *wpt) unsigned char unknown2[] = { 0x01, 0x80 }; /* our personal waypoint counter */ - out_count++; + waypt_out_count++; /* this output format pretty much requires a description * and a shortname @@ -341,7 +343,7 @@ tpg_waypt_pr(const waypoint *wpt) /* and finally 2 unknown bytes */ - if (out_count == waypt_count()) { + if (waypt_out_count == waypt_count()) { /* last point gets 0x0000 instead of 0x0180 */ memset(tbuf, '\0', sizeof(tbuf)); fwrite(tbuf, 1, 2, tpg_file_out); -- 2.30.2